---
title: picklist
description: Creates a picklist schema.
source: /schemas/picklist/picklist.ts
contributors:
  - fabian-hiller
  - romansp
  - sqmasep
---

import { ApiList, Link, Property } from '~/components';
import { properties } from './properties';

# picklist

Creates a picklist schema.

```ts
const Schema = v.picklist<TOptions, TMessage>(options, message);
```

## Generics

- `TOptions` <Property {...properties.TOptions} />
- `TMessage` <Property {...properties.TMessage} />

## Parameters

- `options` <Property {...properties.options} />
- `message` <Property {...properties.message} />

### Explanation

With `picklist` you can validate that the input corresponds to a picklist option. If the input is invalid, you can use `message` to customize the error message.

> `picklist` works in a similar way to <Link href="../enum/">`enum`</Link>. However, in many cases it is easier to use because you can pass an array of values instead of an enum.

## Returns

- `Schema` <Property {...properties.Schema} />

## Examples

The following examples show how `picklist` can be used.

### Language schema

Schema to validate programming languages.

```ts
const LanguageSchema = v.picklist(['JavaScript', 'TypeScript']);
```

### Country schema

Schema to validate country codes.

```ts
const countries = [
  { name: 'Germany', code: 'DE' },
  { name: 'France', code: 'FR' },
  { name: 'United States', code: 'US' },
] as const;

const CountrySchema = v.picklist(
  countries.map((country) => country.code),
  'Please select your country.'
);
```

## Related

The following APIs can be combined with `picklist`.

### Schemas

<ApiList
  items={[
    'array',
    'exactOptional',
    'intersect',
    'lazy',
    'looseObject',
    'looseTuple',
    'map',
    'nonNullable',
    'nonNullish',
    'nonOptional',
    'nullable',
    'nullish',
    'object',
    'objectWithRest',
    'optional',
    'record',
    'set',
    'strictObject',
    'strictTuple',
    'tuple',
    'tupleWithRest',
    'undefinedable',
    'union',
  ]}
/>

### Methods

<ApiList
  items={[
    'assert',
    'config',
    'fallback',
    'getDefault',
    'getDefaults',
    'getFallback',
    'getFallbacks',
    'is',
    'message',
    'parse',
    'parser',
    'pipe',
    'safeParse',
    'safeParser',
  ]}
/>

### Actions

<ApiList
  items={[
    'check',
    'brand',
    'description',
    'flavor',
    'metadata',
    'rawCheck',
    'rawTransform',
    'readonly',
    'title',
    'transform',
  ]}
/>

### Utils

<ApiList items={['entriesFromList', 'isOfKind', 'isOfType']} />
